package com.fy.exam.controller;

import com.fy.core.vo.ApiRest;
import com.fy.exam.dto.ExamCreateDto;
import com.fy.exam.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import com.fy.core.vo.ApiRest;
import com.fy.exam.entity.Exam;
import com.fy.exam.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import com.fy.core.dto.PageDto;
import com.fy.core.vo.PageResult;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author 
 * @since 2023-06-14
 */
@RestController
@CrossOrigin
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private ExamService examService;

    @PostMapping("delete/{examId}")
    public ApiRest deleteExam(@PathVariable("examId") String examId){
       return examService.deleteExam(examId);
    }

    @PostMapping("delete/batchDelete")
    public ApiRest batchDelete(@RequestBody List<Exam> exams) {
        return examService.batchDelete(exams);
    }
    @PostMapping("page")
    public PageResult<Exam> findPage(@RequestBody PageDto<Exam> pageDto){
        System.out.println("pageDto = " + pageDto);
        return examService.findPage(pageDto);
    }


    @PostMapping("create")
    public ApiRest create(@RequestBody ExamCreateDto examCreateDto) {
        return examService.save(examCreateDto);
    }
    @PostMapping("update")
    public ApiRest update(@RequestBody ExamCreateDto examCreateDto){
        return examService.update(examCreateDto);
    }
    @PostMapping("findById/{examId}")
    public ApiRest findById(@PathVariable("examId") String examId){
        return examService.findByExamId(examId);
    }

    @PostMapping("myExams")
    public ApiRest<List<Exam>> myExams(){
        return examService.selectMyExams();
    }

    @GetMapping("preview/{id}")
    public ApiRest<Exam> preview(@PathVariable String id){
        return ApiRest.success(examService.getById(id));
    }
}
